package com.qf.smsplatfrom.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qf.smsplatfrom.constans.ResultCode;
@JsonInclude(JsonInclude.Include.NON_EMPTY)//空的数据不会返回
public class R {
    private int code;//状态码, 通过定义该码,我们可以告诉客户端当前请求的具体状态
    private String msg;//状态码的描述
    private Object data;//当前返回的数据

    public static R setOk() {
        return setOk(null);
    }

    public static R setOk(Object data) {
        R r = new R();
        r.setCode(ResultCode.SUCCESS);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }

    public static R serError() {
        return setError(null);
    }

    public static R setError(Object data) {
        return setError(ResultCode.FAIL, "失败", null);
    }

    public static R setError(Integer code, String msg, Object data) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public R() {
    }
}
